package org.example.intelligent_education.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.intelligent_education.model.CourseInfo;
import org.example.intelligent_education.model.UserInfo;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select* from user where account = #{account}")
    UserInfo queryUserInfoByAccount(String account);
    @Insert("INSERT INTO user (account, password, name) VALUES (#{account}, #{password}, #{name})")
    Integer addUser(String account, String password, String name);
    @Select("SELECT c.* FROM course_info c JOIN recommend r ON c.cid = r.cid WHERE r.uid = #{uid} and c.del=0")
    CourseInfo recommendCourse(int uid);
    @Select("SELECT ci.* FROM course_info ci WHERE ci.cid IN (SELECT uc.cid FROM user_buy uc WHERE uc.uid = #{uid}) and ci.del=0")
    List<CourseInfo> getCoursesByUserId( int uid);

}
